// 首字母大小
export function upperFirst(str) {
  return str.replace(/( |^)[a-z]/g, L => L.toUpperCase())
}

// 下划转和破折号驼峰
export function camelCase(str) {
  return str.replace(/[-_][a-z]/g, str1 => str1.toUpperCase().replace('-', '').replace('_', ''))
}

// 生成唯一字符串
export function uniqueString() {
  const timestamp = +new Date() + ''
  const randomNum = parseInt((1 + Math.random()) * 65536 + '')
  return (+(randomNum + timestamp)).toString(32)
}

// 字符串格式化(%s )
export function sprintf(str) {
  var args = arguments,
    flag = true,
    i = 1
  str = str.replace(/%s/g, function () {
    var arg = args[i++]
    if (typeof arg === 'undefined') {
      flag = false
      return ''
    }
    return arg
  })
  return flag ? str : ''
}
